<template>
  <div class="nav-menu">
    <div class="logo">
      <img class="img" src="~@/assets/img/VueBgc.webp" alt="LOGO" />
      <span class="title">VUE3+TS</span>
    </div>
    <el-menu
      :default-active="path"
      class="el-menu-vertical-demo"
      background-color="#001529"
      :collapse="collapse"
      active-text-color="#409EFF"
      text-color="#fff"
      router
    >
      <template v-for="item in userMenus" :key="item.id">
        <template v-if="item.type === 1">
          <el-sub-menu :index="item.url">
            <template #title>
              <i v-if="item.icon" :class="item.icon"></i>
              <span>{{ item.name }}</span>
            </template>
            <template v-for="subitem in item.children" :key="subitem.id">
              <el-menu-item :index="subitem.url">
                <i v-if="subitem.icon" :class="subitem.icon"></i>
                <span>{{ subitem.name }}</span>
              </el-menu-item>
            </template>
          </el-sub-menu>
        </template>
        <template v-if="item.type === 2">
          <el-menu-item :index="item.url">
            <i v-if="item.icon" :class="item.icon"></i>
            <span>{{ item.name }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import { useStore } from 'vuex'
import { useRoute } from 'vue-router'

export default defineComponent({
  props: {
    collapse: Boolean
  },
  setup() {
    const store = useStore()
    const userMenus = computed(() => store.state.loginModule.userMenus)
    const route = useRoute()
    const path = route.path

    return {
      userMenus,
      path
    }
  }
})
</script>

<style scoped>
.nav-menu {
  width: 211px;
  height: 100%;
  background-color: #03020e;
}
.logo {
  display: flex;
  height: 28px;
  padding: 12px 10px 8px 10px;
  justify-content: flex-start;
  align-items: center;
}
.img {
  height: 100%;
  margin: 0 10px;
}
.title {
  font-size: 16px;
  font-weight: 700;
  color: white;
}
.el-menu-item {
  background-color: #03020e;
}
.el-menu-item:hover {
  background: #d9e4ee !important;
}
.el-menu-item.is-active {
  background: #d9e4ee !important;
}
</style>
